package com.example.fresh_market.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.fresh_market.R;
import com.example.fresh_market.entity.ProdCate;

import java.util.List;

import lombok.Getter;
import lombok.Setter;

public class CateSpinnerAdapter extends ArrayAdapter<ProdCate> {
    private Context mContext;
    private List<ProdCate> mList;
    @Setter
    @Getter
    private ProdCate selectedCate;

    public CateSpinnerAdapter(@NonNull Context context, @NonNull List<ProdCate> objects) {
        super(context, R.layout.spinner_item, objects);
        this.mContext = context;
        mList = objects;
    }

    public CateSpinnerAdapter(@NonNull Context context, int resource, @NonNull List<ProdCate> objects) {
        super(context, resource, objects);
        this.mContext = context;
        mList = objects;
    }

    @Nullable
    @Override
    public ProdCate getItem(int position) {
        return super.getItem(position);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = super.getView(position, convertView, parent);
        TextView cateName = view.findViewById(R.id.spinner_cate_name);
        ProdCate prodCate = mList.get(position);
        if (prodCate != null) {
            cateName.setText(prodCate.getCateName());
        }
        return view;
    }

    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        return getView(position, convertView, parent);
    }
}
